<template>
  <div>
    <!-- <router-link class="link" to="/loginPage">登录账号</router-link> -->
    <div class="top">
      <div class="pic">
        <img src="@/assets/bg.png" alt="" />
      </div>
      <div class="login">
        <div class="login-pic">
          <img src="@/assets/avatar.png" alt="" />
        </div>
        <div class="text">{{nickname}}</div>
        <div class="btn">
            <van-button type="primary" v-if="show" to="/loginPage">去登录</van-button>
            <van-button type="primary" v-if="!show" @click="goout">退出</van-button>
        </div>
      </div>
    </div>
    <div class="list">
      <div class="one">
        <router-link class="link" to="/loginPage">
          <van-icon name="like-o" />
          <span @click.prevent="goCollect">我的收藏</span>
        </router-link>

        <router-link class="link" to="/loginPage">
          <van-icon name="wap-home-o" />
          <span @click.prevent="goRent">我的出租</span>
        </router-link>

        <router-link class="link" to="">
          <van-icon class="link" name="clock-o" />
          <span>看房记录</span>
        </router-link>
      </div>

      <div class="two">
        <router-link class="link" to="">
          <van-icon class="link" name="coupon-o" />
          <span>成为房主</span>
        </router-link>

        <router-link class="link" to="">
          <van-icon class="link" name="contact" />
          <span>个人资料</span>
        </router-link>

        <router-link class="link" to="">
          <van-icon class="link" name="service-o" />
          <span>联系我们</span>
        </router-link>
      </div>
    </div>
    <div class="footer">
      <img src="@/assets/join.png" alt="" />
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  name: "VueJobMy",

  data() {
    return {
      avatar:'',
      nickname:'',
      id:'',
      show:true,
    };
  },
created(){
  this.getUser();
},
  mounted() {
    
  },

  methods: {
    async getUser() {
      const res = await request({
        url: "/user",
      });
      console.log(res);
      this.avatar = res.body.avatar;
      this.nickname = res.body.nickname;
      this.id = res.body.id;
      this.show = false
    },
    goout() {
      this.$dialog.confirm({
        title:'提示',
        message:'是否确定退出'
      }).then(() =>{
        this.$store.commit('user/logout');
        this.show = true;
        this.nickname = '游客'
      })
      .catch(() =>{})
    },
    goCollect(){
      this.$router.push({
        path:'/collect'
      })
    },
    goRent(){
      this.$router.push('/rent')
    }
  },
};
</script>

<style lang="less" scoped>
//     .link {
//   color:gray;;
//   font-size: 16px;
//   padding-right: 170px;
//   padding-top: 200px;
//   float: right;
// }

.pic {
  height: 191px;
  img {
    width: 100%;
  }
}
// 登录区
.top {
  height: 300px;
  position: relative;
  .login {
    top: -55px;
    left: 27px;
    position: relative;
    width: 278px;
    height: 165px;
    text-align: center;
    background-color: #fff;
    box-shadow: 0px 0px 15px 5px #ccc;
    padding: 0 20px;
    .login-pic {
      position: relative;
      transform: translateY(-50%);
      border-radius: 50%;
      width: 70px;
      height: 70px;
      border: 5px solid #f5f5f5;
      display: inline-block;
      box-shadow: 0 2px 2px #bdbdbd;
      img {
        width: 100%;
      }
    }

    .text {
      font-size: 14px;
      color: #333;
    }
    .btn {
      padding-top: 15px;
      button {
        background-color: #21b97a;
        border: 0px;
        width: 70px;
        height: 30px;
        border-radius: 6px;
        span {
          color: #fff;
          width: 100%;
          // padding: 0 10px  ;
          font-size: 13px;
        }
      }
    }
  }
}
// 列表区
.list {
  span {
    padding-top: 10px;
    font-size: 13px;
  }
  .one {
    display: flex;
    padding: 15px 0;
    height: 100%;
    color: #333;
    .link {
      font-size: 22px;
    }
    a {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 125px;
      height: 65px;
      color: #333;
    }
  }
  .two {
    display: flex;
    padding: 15px 0;
    .link {
      font-size: 22px;
    }
    a {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 125px;
      height: 65px;
      color: #333;
    }
  }
}
.footer {
  width: 345px;
  height: 85px;
  margin-top: 10px;
  margin-left: 13px;
  img {
    width: 100%;
    text-align: center;
  }
}
</style>
